﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace BitmapReader
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = "smile.bmp";
            FileStream file = null;
            try
            {
                file = new FileStream(path, FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(file);
                Console.WriteLine(path + " file information :");
                char c = br.ReadChar();
                char d = br.ReadChar();
                if (c == 'B' && d == 'M')
                {
                    Console.WriteLine(" -Magic number is correct.");
                    file.Seek(16, SeekOrigin.Current);
                    int largeur = br.ReadInt32();
                    int hauteur = br.ReadInt32();
                    Console.WriteLine(" -Dimensions : {0} x {1}", largeur, hauteur);
                    file.Seek(2, SeekOrigin.Current);
                    int bperp = br.ReadInt16();
                    Console.WriteLine(" -Number of bits per pixel : {0}", bperp);
                }
                else
                    Console.WriteLine(" -Magic number is incorrect.");
            }
            catch (IOException exc)
            {
                Console.WriteLine("Erreur : " + exc);
                Console.ReadLine();
            }
        }
    }
}
